package com.ruoyi.project.mall.api;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.mall.service.MallShopTypeService;
import com.ruoyi.project.mall.service.MallShopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/api/shop")
public class ApiShopController {

    @Autowired
    private MallShopUserService mallShopUserService;
    @Autowired
    private MallShopTypeService mallShopTypeService;

    /**
     *  获取商家行业类别和商家属性
     * @param params 0行业类别1行业属性
     * @return
     */
    @PostMapping( "/getShopType")
    @ResponseBody
    public R getShopType(@RequestBody Map<String, Object> params){

        try{
            if (!params.containsKey("status") || StringUtils.isBlank(params.get("status").toString())




            ) {
                return R.error("参数错误");
            }
            return  mallShopTypeService.getShopType(params);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }

    /***
     * 店铺需求
     * @param params userId 没有传-1
     * @return
     */
    @PostMapping( "/getShopNeed")
    @ResponseBody
    public R getShopNeed(@RequestBody Map<String, Object> params){

        try{
            if (!params.containsKey("shopId") || StringUtils.isBlank(params.get("shopId").toString())||
                    !params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())



            ) {
                return R.error("参数错误");
            }
            return  mallShopUserService.getShopNeed(params);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }

    /***
     * 获取店铺商品
     * @param params
     * @return
     */
    @PostMapping( "/getShopGoods")
    @ResponseBody
    public R getShopGoods(@RequestBody Map<String, Object> params){

        try{
            if (!params.containsKey("shopId")
            ) {
                return R.error("参数错误");
            }
            return  mallShopUserService.getShopGoods(params);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }


    /***
     * 店铺详情
     * @param params userId 用户id 没有传-1
     * @return
     */
    @PostMapping( "/getShopInfo")
    @ResponseBody
    public R getShopInfo(@RequestBody Map<String, Object> params){

        try{
            if (!params.containsKey("shopId") || StringUtils.isBlank(params.get("shopId").toString())
                    ||!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())


            ) {
                return R.error("参数错误");
            }
            return  mallShopUserService.getShopInfo(params);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }
}
